﻿/*
	S.Sams Lifexperience
	-----------------------------------------------------
	Copyright (C) 2002 - 2008 S.Sams Lifexperience!
	All rights reserved
	Email:		Cassams@gmail.com / S.Sams@msn.com
	WebSite:	Http://lab.travelive.com.cn/
	Msn:		S.Sams@Msn.com
	Author:		Sam Shen
*/
function onOver(obj)
{
obj.className="MsgClose_hover";
}

 function onOut(obj)
{
obj.className="MsgClose";
}
 function CloseDiv(obj)
 {
 }
(function($) {
    $.fn.tooltip = function(options){
        var opts = $.extend({}, $.fn.tooltip.defaults, options);
        $('body').append('<div class="msgBox" id="DynamicDiv"><img src="Resources/Images/hint-dart.gif" alt="" class="tooltipsImageStyle"/><div id="ShowResultDiv" class="tooltipsCenterOK"><div class="tootipHeader" id="tootipHeaderTemp"></div> <div class="MsgClose" onclick="CloseDiv(this)" onmouseover="onOver(this)" onmouseout="onOut(this)" ></div><div class="tooltipsDivision"></div><div class="tooltipshowpanel"></div></div></div>');
       $(document).blur(function(){$('.msgBox').hide();});
        this.each(function(){
            // Tooltip
            if($(this).attr('tip') != undefined)
            {
                $(this).focus(function(){
                 $('.msgBox')
                        .css({display:'block'});
                    $('.msgBox')
                        .css({left:$.getLeft(this)+'px',top:$.getTop(this)+'px'});
                                  var title=$(this).attr('tip').split("[&]");
                    $('.tooltipshowpanel').html(title[0]);
                    document.getElementById("tootipHeaderTemp").innerHTML=title[1];
                    $('.tooltipshowpanel').fadeIn("fast");
                    if($(this).className=='tooltipinputerr'); 
                              $(this).removeClass('tooltipinputerr');           
                },

                function(){
                 
                });
                $(this).blur(function(){
                    $('.msgBox')
                        .css({display:'none'});
                    $('.tooltipshowpanel').html($(this).attr('tip'));
                    $('.tooltipshowpanel').fadeIn("fast");
                     var thisReg = new RegExp($(this).attr('reg'));
                    if(!thisReg.test(this.value))
                    {
                       var selectList=document.getElementById($(this).attr('id')).type.split('-');
                       if(selectList.length>0 && selectList[0]=='select')
                       {
                            // $(this).addClass('tooltipSelecterr');
                       }
                       else
                       {
                        $(this).addClass('tooltipinputerr');
                       }
                    }
                    if($(this).attr('toupper') == 'true')
                    {
                        this.value = this.value.toUpperCase();
                    }
                },
               
                function(){
                });
                $(this).change(function(){
                    $('.msgBox')
                        .css({display:'none'});
                    $('.tooltipshowpanel').html($(this).attr('tip'));
                    $('.tooltipshowpanel').fadeIn("fast");
                     var thisReg = new RegExp($(this).attr('reg'));    
                    var selectList=document.getElementById($(this).attr('id')).type.split('-');
                    if(selectList.length>0 && selectList[0]=='select')
                    {
                        if(!thisReg.test(this.value))
                        {
                           document.getElementById($(this).attr('id')).style.backgroundColor="#e55d4c"; 
                           for(var index=1;index<document.getElementById($(this).attr('id')).options.length;index++)
                           {
                            document.getElementById($(this).attr('id')).options[index].style.backgroundColor="#ffffff";  
                           }  
                        }
                        else
                        {
                           document.getElementById($(this).attr('id')).style.backgroundColor="#ffffff";
                        }
                    }
                },
               
                function(){
                });
                 
            }
        });
        // Form Check
        if(opts.onsubmit)
        {
            $('form').submit( function () {
                var isSubmit = true;
                $(this).find('input[reg]').each(function(){  
                    
                    var thisReg = new RegExp($(this).attr('reg'));
                    if(!thisReg.test(this.value))
                    {
                        $(this).removeClass('tooltipinputok').addClass('tooltipinputerr');
                        isSubmit = false;
                    }
                    
                });
                $(this).find('select[reg]').each(function(){  
                    
                    var thisReg = new RegExp($(this).attr('reg'));  
                    var IsValid=true;
                    var selectAttribute=document.getElementById($(this).attr('id')).getAttribute('IsValid');
                    if(selectAttribute!=null && selectAttribute=='N')
                    {
                     IsValid=false;
                   
                    }
                    if(IsValid)
                    {
                        if(!thisReg.test(this.value))
                        {
                               document.getElementById($(this).attr('id')).style.backgroundColor="#e55d4c"; 
                               for(var index=1;index<document.getElementById($(this).attr('id')).options.length;index++)
                               {
                                document.getElementById($(this).attr('id')).options[index].style.backgroundColor="#ffffff";  
                               } 
                            isSubmit = false;
                        }
                    }
                    
                });
                if(isBack)
                {
                isSubmit = true;
                }
                if(!isBack)
                { 
                    if(isSubmit)
                    {
                        if((document.getElementById(IclientId+"txtPassword")!=null)&&(document.getElementById(IclientId+"txtComfirmPassword")!=null))
                        {
                            if(document.getElementById(IclientId+"txtPassword").value!=document.getElementById(IclientId+"txtComfirmPassword").value)
                            {
                            isSubmit=false;
                            alert("Please enter a confirm password as same as the password.");
                            }
                        }
                    }
                }
                return isSubmit;
            } ); 
        }
    };
    
    $.extend({
        getWidth : function(object) {
            return object.offsetWidth;
        },

        getLeft : function(object) {
            var go = object;
            var oParent,oLeft = go.offsetLeft;
            while(go.offsetParent!=null) {
                oParent = go.offsetParent;
                oLeft += oParent.offsetLeft;
                go = oParent;
            }
            return oLeft+object.offsetWidth+10;
        },

        getTop : function(object) {
            var go = object;
            var oParent,oTop = go.offsetTop;
            while(go.offsetParent!=null) {
                oParent = go.offsetParent;
                oTop += oParent.offsetTop;
                go = oParent;
            }
            return oTop-10;
        },
        getDisplay:function(object)
        {
          return 'none';
        },
        onsubmit : true
    });  
    $.fn.tooltip.defaults = { onsubmit: true };
    
    $(document).ready(function() {jQuery('input[tip],input[reg],select[tip],select[reg]').tooltip()});
    
})(jQuery)